//
//  ViewController.m
//  UI22_数据库
//
//  Created by dllo on 16/1/7.
//  Copyright © 2016年 www.lanou3g.com. All rights reserved.
//

#import "ViewController.h"
#import "DataBaseManager.h"
#import "Movie.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
}
#pragma mark - 打开数据库
- (IBAction)Open:(id)sender {
    //创建单例对象
    DataBaseManager *dbManager = [DataBaseManager shareInstance];
    //打开数据库
    [dbManager openDB];
}

#pragma mark - 关闭数据库
- (IBAction)Close:(id)sender {
    [[DataBaseManager shareInstance] CloseDB];
}

#pragma mark - 创建表

- (IBAction)CreateTable:(id)sender {
    
    [[DataBaseManager shareInstance] CreateTable];
}
#pragma mark - 删除表
- (IBAction)dropTable:(id)sender {
    [[DataBaseManager shareInstance] DropTable];
}

#pragma mark - 添加
- (IBAction)insert:(id)sender {
    // movie对象
    Movie *m = [[Movie alloc]init];
    m.movieName = @"唐人街探案";
    m.pubdate = @"2016-1-6";
    // 插入
    [[DataBaseManager shareInstance] insertMovie:m];
}

#pragma mark - 删除
- (IBAction)delete:(id)sender {
    [[DataBaseManager shareInstance] deleteMovieWithId:2];
}

#pragma mark - 更新
- (IBAction)Update:(id)sender {
    Movie *newM = [[Movie alloc]init];
    newM.movieName = @"STAR WARS";
    newM.pubdate = @"2020202020";
    
    [[DataBaseManager shareInstance] updateMovie:newM withId:5];
}

#pragma mark - 查询
- (IBAction)Select:(id)sender {
    NSMutableArray *arr = [[DataBaseManager shareInstance] select];
    for (Movie *m in arr) {
        NSLog(@"%@ %@ %ld", m.movieName, m.pubdate, m.movieId);
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
